<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 1. 加下划线
    // 2. 使用闭包
    function createPerson(name) {
      let _age = 12;
      class Person {
        // name是公有属性
        // age 是私有属性
        constructor(props) {
          this.name = props.name;
        }
        sayAge() {
          return _age;
        }
        setAge(newAge) {
          _age = newAge;
        }
      }
      return new Person({ name });
    }
    const p = createPerson('zs')
    console.log(p);
  </script>
</body>

</html>